<?php
namespace Admin\Controller;

use Common\Controller\AdminbaseController;

class CrawlerController extends AdminbaseController {
    protected $anchor_model;

    public function _initialize(){
        parent::_initialize();
        $this->anchor_model=D("Common/Anchor");
    }
	
    public function index(){


        $count=$this->anchor_model->count();
        $page = $this->page($count, 15);
        $anchors=$this->anchor_model
            ->limit($page->firstRow . ',' . $page->listRows)
            ->order("inputtime DESC")
            ->select();
        $this->assign("anchors",$anchors);
        $this->assign("page", $page->show('Admin'));
        $this->display();
    }

    // 后台Anchor删除
    public function delete(){
        if(isset($_GET['id'])){
            $id = intval(I("get.id"));
            if ($this->anchor_model->where("id=$id")->delete()!==false) {
                $this->success("删除成功！");
            } else {
                $this->error("删除失败！");
            }
        }
        if(isset($_POST['ids'])){
            $ids=join(",",$_POST['ids']);
            if ($this->anchor_model->where("id in ($ids)")->delete()!==false) {
                $this->success("删除成功！");
            } else {
                $this->error("删除失败！");
            }
        }
    }

    // 后台Anchor审核
    public function check(){
        if(isset($_POST['ids']) && $_GET["check"]){
            $data["status"]=1;

            $ids=join(",",$_POST['ids']);

            if ( $this->anchor_model->where("id in ($ids)")->save($data)!==false) {
                $this->success("审核成功！");
            } else {
                $this->error("审核失败！");
            }
        }
        if(isset($_POST['ids']) && $_GET["uncheck"]){

            $data["status"]=0;
            $ids=join(",",$_POST['ids']);
            if ( $this->anchor_model->where("id in ($ids)")->save($data)!==false) {
                $this->success("取消审核成功！");
            } else {
                $this->error("取消审核失败！");
            }
        }
    }
}